/**
 * Created by sun on 2016/8/4.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');




    app.useModule("ui.table");



    var datepicker = require('datepicker');
    app.controller('sys_contractsCtrl', ['$scope','$http','$filter' ,function ($scope, $http,$filter) {
        $scope.orderParams = {
            url: "/admin/contracts/getList"
        };
        datepicker($scope);

        //创建
        $scope.addOrderModal=function(){
            $scope.orderModal = !$scope.orderModal ;
        };

        //全局查询
        $scope.search = function() {
            $scope.ctrlScope.itemsearch.beginDateTime=$scope.ctrlScope.itemsearch.beginDateTimex;
            $scope.ctrlScope.itemsearch.endDateTime= $scope.ctrlScope.itemsearch.endDateTimex;
            $scope.ctrlScope.itemsearch.beginDateTime=$filter('date')($scope.ctrlScope.itemsearch.beginDateTime,'yyyy-MM-dd');
            $scope.ctrlScope.itemsearch.endDateTime=$filter('date')($scope.ctrlScope.itemsearch.endDateTime,'yyyy-MM-dd');
            //表格查询参数设置
            $scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;
            //表格刷新
            $scope.orderParams.reload();
        };

        //全局查询重置
        $scope.reset=function(){
            $scope.orderParams.ajaxParam={};
            $scope.ctrlScope.itemsearch={};
            $scope.orderParams.reload();
        };

        //新建
        $scope.adoptAdd = function(){
            var parm=$scope.add;
            $http({
                method: 'POST',
                url: "/admin/contracts/add",
                data:parm,
            }).success(function(data) {
                console.info(data);
                alert("创建成功！");
                $scope.orderModal = !$scope.orderModal;
                $scope.orderParams.reload();
            }).error(function(data) {
            });
        };
        //编辑
        $scope.modifyModal = function(id){
            $scope.detailsModal= !$scope.detailsModal;
            $scope.getOne(id);
        };
        //单个查询
        $scope.getOne = function(id){
            $http({
                method: 'POST',
                url: "/admin/contracts/getSingle",
                data: {
                    id:id
                }
            }).success(function(data) {
                console.info(data);
                $scope.list=data;
            }).error(function(data) {
            });
        };
        //保存
        $scope.saveSubmit = function(){
            var parm=$scope.list;
            $http({
                method: 'POST',
                url: "/admin/contracts/updateStatus",
                data:parm,
            }).success(function(data) {
                console.info(data);
                $scope.detailsModal= !$scope.detailsModal;
                $scope.orderParams.reload();
            }).error(function(data) {
            });
        };
        //下载合同
        $scope.getContract=function(url){
                        window.open(url);
        };
    }]);


});